<?php

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			includes/custom/selectuploadedimage.php
#	FUNCTION:		Custom handler for the Select Uploaded Image page
#	AUTHOR:			Cameron Morrow
#	CREATED:		08/09/2005
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Header
addContent("<h2>Select an uploaded image:</h2>");

# Get list of images
$uploaded_images = getUploadedFiles();
$uploaded_images = $uploaded_images[0];

# Get active image
$selected_image = (@$_GET["selected"]) ? $_GET["selected"] : "";

# Get index of selected image
$selected_image_index = array_search($selected_image, $uploaded_images);
$selected_image_index = ($selected_image_index === false) ? -1 : $selected_image_index;

# Get field ID
$input_field = (@$_GET["field"]) ? $_GET["field"] : "";

# Set up javascript
addContent("<script language=\"javascript\" type=\"text/javascript\">\nvar selected_image_id = " . $selected_image_index . ";\nvar image_field = \"" . $input_field . "\";\n</script>");

# Draw images
addContent("<a name=\"start\"></a><table class=\"selectimagelist\"><tr>");

# For each image
foreach ($uploaded_images as $image_id => $uploaded_image) {

	addContent("<td class=\"" . (($uploaded_image == $selected_image) ? "selected" : "") . "\" id=\"image-" . $image_id . "\"><a href=\"javascript:selectImageListImage(" . $image_id . ");\"><img width=\"70\" src=\"../assets/uploads/" . $uploaded_image . "\" alt=\"" . $uploaded_image . "\" /><br />" . $uploaded_image . "</a></td>");

	# If fourth in a row
	if (($image_id + 1) % 3 == 0) {
		addContent("<td class=\"end\"><a href=\"#start\">Start</a><a href=\"#end\">End</a></td></tr><tr>");
	}
}

# End
addContent("</tr></table>");

# Prompt
addContent("<p style=\"clear: both;\">Select an image to use above, then click 'Use this Image' when you are finished. Alternatively, click 'Use no image' to not use an image at all.</p>");

# Buttons
addContent("<a name=\"end\"></a><form name=\"imageselectform\" id=\"imageselectform\" action=\"#\" method=\"get\">" .
	"<input type=\"button\" id=\"useimagebutton\" value=\"Use this image\"" . (($selected_image_index == -1) ? "disabled=\"disabled\"" : "") . " onclick=\"finishSelectingImageListImage();\" /> " .
	"<input type=\"button\" value=\"Use no image\" onclick=\"finishSelectingImageListImage(true);\" />" .
	"</form>");

?>